package com.example.myapplication.tutorial

import android.util.Log
import com.facebook.litho.annotations.Event
import com.facebook.litho.annotations.FromTrigger
import com.facebook.litho.annotations.OnTrigger
import com.facebook.litho.sections.Children
import com.facebook.litho.sections.SectionContext
import com.facebook.litho.sections.annotations.GroupSectionSpec
import com.facebook.litho.sections.annotations.OnCreateChildren
import com.facebook.litho.sections.common.SingleComponentSection


/**
 * TODO 简要描述
 * @author wkm @ Zebra Inc.
 * @since 09-20-2020
 */

@Event
class TEvent {

    @JvmField
    var data: Int? = null
}

@GroupSectionSpec
object ListSectionSpec {


    @OnCreateChildren
    fun onCreateChildren(c: SectionContext): Children {
        val builder = Children.create()
        for (i in 0..31) {
            builder.child(
                SingleComponentSection.create(c)
                    .key("$i")
                    .component(ListItem.create(c).build())
            )
        }
        return builder.build()
    }

    @OnTrigger(TEvent::class)
    fun onTrigger(c: SectionContext, @FromTrigger data: Int) {
        Log.e("TAG", "$data")
    }

}